package view_api

import (
	"gin-vue-admin/global"
	"gin-vue-admin/model"
	"gin-vue-admin/model/request"
	"gin-vue-admin/model/response"
	"gin-vue-admin/service"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"strconv"
)
func FindConfig(c *gin.Context) {
	var config model.Config
	_ = c.ShouldBindQuery(&config)
	config.ID = 35
	if err, reconfig := service.GetConfig(config.ID); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"reconfig": reconfig}, c)
	}
}
func IndexPic(c *gin.Context)  {
	returnMap := map[string]interface{}{}
	var pageInfo request.BannerSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if err, list, _ := service.GetBannerInfoList(pageInfo); err != nil {
		response.FailWithMessage("获取失败", c)
	} else {
		returnMap[`bannerList`] = list
		//response.OkWithDetailed(response.PageResult{
		//	List:     list,
		//	Total:    total,
		//	Page:     pageInfo.Page,
		//	PageSize: pageInfo.PageSize,
		//}, "获取成功", c)
	}
	var BInfo request.BrandComSearch
	_ = c.ShouldBindQuery(&BInfo)
	if err, list, _ := service.GetBrandComInfoList(BInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
		response.FailWithMessage("获取失败", c)
	} else {
		returnMap[`brand_com`] = list
	}

	var cInfo request.CoopComSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if err, list, _ := service.GetCoopComInfoList(cInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
		response.FailWithMessage("获取失败", c)
	} else {
		returnMap[`coop_com`] = list
	}
	var CoopComTwoSearchInfo request.CoopComTwoSearch
	_ = c.ShouldBindQuery(&CoopComTwoSearchInfo)
	if err, list, _ := service.GetCoopComTwoInfoList(CoopComTwoSearchInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
		response.FailWithMessage("获取失败", c)
	} else {
		returnMap[`coop_com_two`] = list
	}
	response.OkWithData(returnMap,c)
}
func IndexData(c *gin.Context){
	returnData := map[string]interface{}{}

	//获取审核通过的商品企业名称

	page := c.Query(`page`)
	pageInt,_ := strconv.Atoi(page)
	pageSize := c.Query(`pageSize`)
	pageSizeInt,_ := strconv.Atoi(pageSize)
	if pageInt == 0 {
		pageInt = 1
	}
	if pageSizeInt == 0{
		pageSizeInt = 5
	}
	var info request.UserGoodsSearch
	info.Status = 3
	info.Page = pageInt
	info.PageSize = pageSizeInt
	_,returnData[`new_public`],returnData[`new_public_total`]=service.GetUserGoodsQy(info,`id desc`)
	_,returnData[`new_order`] = service.GetOrderUserQy(`id desc`)
	_,returnData[`new_goods`],_ = service.GetUserGoodsInfoList(info,`id desc`)
	var new_index request.UserIndexSearch
	new_index.Page = pageInt
	new_index.PageSize = pageSizeInt
	new_index.Status = 3
	_,returnData[`new_index`],returnData[`new_index_total`] = service.GetUserIndexInfoList(new_index,`id desc`)
	var all_type request.CTypesSearch
	_,returnData[`all_types`],_ = service.GetCTypesInfoList(all_type)

	_,returnData[`new_users`] = service.FindNewUser(pageInt,pageSizeInt)
	returnData[`sum_money`],_ = service.UserProjectTotalMoney()
	response.OkWithData(returnData,c)
}
